/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GraphsWindowPackage;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import AlertSystem.Window;
import javafx.scene.Node;

/**
 * @author quang
 */

public class ChoiceBlock extends Window {

    public var choices: String[];
    public var infos: String[];
    public var questionText: String;
    public var active: Boolean;

    //--------------------------------------------

    def group = ToggleGroup{};
    def radioButtons = for (i in [0..sizeof choices - 1])
    RadioButton  {
        var stage: Stage = null;
        text: choices[i]
        font: font2
        toggleGroup: group
        onMouseEntered: function(e: MouseEvent): Void {
//            if (active)
            stage = Stage {
                onClose: function () { stage = null; }
                x: e.screenX
                y: e.screenY + 15
                style: StageStyle.UNDECORATED
                scene: Scene {
                    fill: Color.YELLOW
                    content: [
                        Text {
                            font: font1
                            content: "\n{choices[i]}:\n{infos[i]}"
                            wrappingWidth: assessmentBoxWidth * 0.5
                        }
                    ]
                }
            }
        }
        onMouseExited: function(e: MouseEvent): Void {
//            if (active)
            stage.close();
        }
    }

    public function reset() {
        for (i in [0..sizeof radioButtons - 1]){
            radioButtons[i].selected = false;
        }
    }

    public function getSelectedChoice(): Integer {
        var ret = -1;
        for (i in [0..sizeof radioButtons - 1]){
            if (radioButtons[i].selected == true) {
                ret = i;
                break;
            }
        }
        return ret;
    }

    public override function create(): Node {
        def question = Text {
            font: font2
            content: questionText
            fill: Color.RED
            wrappingWidth: assessmentBoxWidth
        }


        return VBox {
            spacing: 5
            content: bind [
                question,
                HBox {
                    spacing: 10
                    content: radioButtons
                }
            ]
        }
    }
}
